package com.ugrow.ugrowcommunity.activity.courseselection.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.ugrow.ugrowcommunity.R;
import com.ugrow.ugrowcommunity.activity.courseselection.bean.CourseBean;
import com.ugrow.ugrowcommunity.activity.courseselection.bean.Data;
import com.ugrow.ugrowcommunity.databinding.CourseSelectionItemBinding;

import java.util.ArrayList;
import java.util.List;

public class CourseAdapter extends RecyclerView.Adapter<CourseAdapter.Holder> {

    private OnItemClick onItemClick;
    private Context context;
    private List<Data> list;

    public CourseAdapter(Context context,List<Data> list){
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public CourseAdapter.Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new Holder(LayoutInflater.from(context).inflate(R.layout.course_selection_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull CourseAdapter.Holder holder, @SuppressLint("RecyclerView") int position) {
        holder.itemBinding.className.setText(list.get(position).getCName());
        holder.itemBinding.classHours.setText(String.valueOf(list.get(position).getCTime()));
        holder.itemBinding.classNature.setText(list.get(position).getCNature());
        holder.itemBinding.selection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemClick.onClick(holder.itemBinding.selection,position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }



    public class Holder extends RecyclerView.ViewHolder {
        private CourseSelectionItemBinding itemBinding;

        public Holder(@NonNull View itemView) {
            super(itemView);
            itemBinding = CourseSelectionItemBinding.bind(itemView);
        }
    }

    public void setOnItemClick(OnItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    public interface OnItemClick{
        void onClick(TextView selection,int position);
    }


}
